Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid trying to emit anonymous classish/expando functions as assignments #55472

Merged
merged 3 commits into from
Aug 28, 2023

Conversation

weswigham
Copy link
Member

Fixes #55172

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 22, 2023
if (!context.remappedSymbolRefernces) {
context.remappedSymbolRefernces = new Map();
}
context.remappedSymbolRefernces.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle the not-anonymous-but-still-an-expression case where you could use that local name to refer to the type of the expando-thing as a whole. Because it'd be odd if just adding a name to the function expression made this transform stop working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is for cases like

const f = function g() { }
f.p = 1

Does remappedSymbolReferences record g? When would g show up in the declaration emit?

Edit: Looking at the test cases, it's actually g -> f so that when a constructor function g returns g, it serialises as f.

src/compiler/checker.ts Outdated Show resolved Hide resolved
src/compiler/checker.ts Show resolved Hide resolved
src/compiler/checker.ts Outdated Show resolved Hide resolved
if (!context.remappedSymbolRefernces) {
context.remappedSymbolRefernces = new Map();
}
context.remappedSymbolRefernces.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is for cases like

const f = function g() { }
f.p = 1

Does remappedSymbolReferences record g? When would g show up in the declaration emit?

Edit: Looking at the test cases, it's actually g -> f so that when a constructor function g returns g, it serialises as f.

@weswigham weswigham merged commit 5ce34ca into microsoft:main Aug 28, 2023
19 checks passed
@weswigham weswigham deleted the js-declarations-global-file branch August 28, 2023 19:16
snovader pushed a commit to mestro-se/TypeScript that referenced this pull request Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tsc with allowJs reports TS9005 error for anonymous constructor functions
3 participants